<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<%@ include file="header.jsp"%>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
	<form id="formId" class="layui-form layui-form-pane" action="">
	  <div class="layui-form-item">
	    <label class="layui-form-label">用户名</label>
	    <div class="layui-input-block">
	      <input type="text" name="name" autocomplete="off" placeholder="请输入用户名" class="layui-input">
	    </div>
	  </div>
	  <div class="layui-form-item">
	    <label class="layui-form-label">年龄</label>
	    <div class="layui-input-block">
	      <input type="text" name="age" autocomplete="off" placeholder="请输入年龄" class="layui-input">
	    </div>
	  </div>
	   <div class="layui-form-item">
	    <label class="layui-form-label">密码</label>
	    <div class="layui-input-block">
	      <input type="text" name="password" autocomplete="off" placeholder="请输入密码" class="layui-input">
	    </div>
	  </div>
	   <div class="layui-form-item">
	    <label class="layui-form-label">邮箱</label>
	    <div class="layui-input-block">
	      <input type="text" name="email" autocomplete="off" placeholder="请输入邮箱" class="layui-input">
	    </div>
	  </div>
	  <div class="layui-form-item">
	    <label class="layui-form-label">部门</label>
	    <div class="layui-input-block">
	      <select name="departmentId">
	        <option value="">请选择部门</option>
	       	<c:forEach items="${departmentList}" var="department">
		        <option value="${department.id}">${department.name}</option>
	       	</c:forEach>
	      </select>
	    </div>
	   </div> 
	   <div class="layui-form-item">
	     <label class="layui-form-label">请选择角色</label>
	     <div class="layui-input-block">
	     	<c:forEach items="${roleList}" var="role">
		         <input type="checkbox" name="roleIds" value="${role.id}" title="${role.name}">
	       	</c:forEach>
	     
	     </div>
	   </div>
	  <input  type="button" class="layui-btn" value="添加" onclick="submitForm()">
	</form>
	
	
	<script type="text/javascript">
		layui.use(['form', 'laydate'], function() {
			var form = layui.form;
			
			
		});
	
		function submitForm(){
			$.post(
				'${path}/user?method=insert',
				$('#formId').serialize(),
				function(jsonResult) {
					console.log(jsonResult);
					if (jsonResult.code == 0) {
						console.log(jsonResult);
						mylayer.okMsg(jsonResult.msg);
						
						//当你在iframe页面关闭自身时获得当前弹出框的index索引
		                var index = parent.layer.getFrameIndex(window.name);
	                     
	                     // js一个方法，定时器，1000毫秒之后自动执行function里面的代码
	                     setTimeout(function() {
	                         // 关闭弹出层
	                         parent.layer.close(index);
	                         // 刷新父页面
	                         window.parent.location.reload();
	                     }, 1000);
					} else {
						mylayer.errorMsg(jsonResult.msg);
					}
				},
				'json'
			);
		}

	</script>
</body>
</html>